package com.lujieni.nio.c1;

import java.nio.ByteBuffer;

public class TestByteBufferRead {

    public static void main(String[] args) {
        ByteBuffer allocate = ByteBuffer.allocate(10);

        allocate.put(new byte[]{'a','b','c','d','e'});

        allocate.flip();

        allocate.get(new byte[3]); //一次性读取3个字节

        char result = (char)allocate.get(); // 读到d

        System.out.println(result);


        allocate.mark(); // 记录e的下标

        result = (char)allocate.get(); //读取e

        System.out.println(result);

        allocate.reset();

        result = (char)allocate.get(); //再次读取读取e

        System.out.println(result);


    }
}
